package com.cqc.paoclient.ui.mime;

import com.cqc.paoclient.http.RetrofitHelper;
import com.cqc.paoclient.model.BaseMsgModel;
import com.cqc.paoclient.model.MyProfileModel;
import com.cqc.paoclient.util.LogUtil;
import com.cqc.paoclient.util.NetErrorUtil;

import io.reactivex.Scheduler;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by cui on 2017/11/23.
 */

public class Tab3FragPresenter extends Tab3FragContract.Presenter {

    @Override
    public void getMyProfile() {
        disposable.add(RetrofitHelper.createUserApi().getMyProfile()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<MyProfileModel>() {
                    @Override
                    public void accept(MyProfileModel myProfileModel) throws Exception {
                        mView.getMyProfileSucc(myProfileModel);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.getMyProfileFail(NetErrorUtil.handleThrowable(throwable));
                    }
                })
        );
    }

    @Override
    public void loginOut() {
        disposable.add(RetrofitHelper.createUserApi().logout()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<BaseMsgModel>() {
                    @Override
                    public void accept(BaseMsgModel baseMsgModel) throws Exception {
                       mView.getLogOutSucc(baseMsgModel);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.getLogOutFail(NetErrorUtil.handleThrowable(throwable));
                    }
                }));
    }
}
